package cn.uexpo.lhz.biz.impl;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



import cn.uexpo.lhz.biz.EquipmentBiz;
import cn.uexpo.lhz.common.oldBase.BOException;
import cn.uexpo.lhz.common.oldUtils.PageRequest;
import cn.uexpo.lhz.common.oldUtils.PageResult;
import cn.uexpo.lhz.common.oldUtils.PageUtils;
import cn.uexpo.lhz.dao.EquipmentMapper;
import cn.uexpo.lhz.domain.Equipment;
import cn.uexpo.lhz.domain.EquipmentExample;
import cn.uexpo.lhz.domain.Equipment;

@Service
public class EquipmentBizImpl implements EquipmentBiz {

	@Autowired
	private EquipmentMapper equipmentMapper;

	@Override
	public int insert(Equipment record) throws BOException {
		return equipmentMapper.insert(record);

	}

	@Override
	public int insertSelective(Equipment record) throws BOException {
		return equipmentMapper.deleteByPrimaryKey(record.getId());

	}

	@Override
	public int deleteByPrimaryKey(Integer id) throws BOException {
		return equipmentMapper.deleteByPrimaryKey(id);

	}

	@Override
	public int deleteEntity(Equipment record) throws BOException {
		return equipmentMapper.deleteByPrimaryKey(record.getId());

	}

	@Override
	public int deleteByIds(List<Integer> ids) throws BOException {
		int no=0;
		if (null!=ids) {
			for (Integer id : ids) {
				no=equipmentMapper.deleteByPrimaryKey(id);
				if (no==0) {
					throw new RuntimeException("删除失败。") ;
				}
			}
		}

		return no;
	}

	@Override
	public int delete(List<Equipment> records) throws BOException {
		int no=0;
		if (null!=records&&records.size()>0){
			for (Equipment equipmentEntity : records) {
				no=equipmentMapper.deleteByPrimaryKey(equipmentEntity.getId());
				if (no==0) {
					throw new RuntimeException("删除失败。") ;
				}
			}
		}

		return no;
	}

	@Override
	public int deleteByExample(EquipmentExample example) throws BOException {
		return equipmentMapper.deleteByExample(example);

	}

	@Override
	public int updateByPrimaryKey(Equipment record) throws BOException {
		return equipmentMapper.updateByPrimaryKey(record);

	}

	@Override
	public int updateByPrimaryKeySelective(Equipment record) throws BOException {
		return equipmentMapper.updateByPrimaryKeySelective(record);

	}

	@Override
	public int updateByExampleSelective(Equipment record, EquipmentExample example) throws BOException {
		return equipmentMapper.updateByExampleSelective(record, example);

	}

	@Override
	public int updateByExample(Equipment record, EquipmentExample example) throws BOException {
		return equipmentMapper.updateByExample(record, example);

	}

	@Override
	public Equipment selectByPrimaryKey(Integer id) throws BOException {
		return equipmentMapper.selectByPrimaryKey(id);

	}

	@Override
	public Equipment selectByUniqueCode(String uniqueCode) throws BOException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Equipment> selectByExample(EquipmentExample example) throws BOException {
		return equipmentMapper.selectByExample(example);

	}

	@Override
	public long countByExample(EquipmentExample example) throws BOException {
		return equipmentMapper.countByExample(example);

	}

	@Override
	public PageResult findPage(PageRequest pageRequest, EquipmentExample example) throws BOException {
		int pageNum = pageRequest.getPage();
		int pageSize = pageRequest.getLimit();
	    PageHelper.startPage(pageNum, pageSize);
	    List<Equipment> records = (List<Equipment>) equipmentMapper.selectByExample(example);
	    return PageUtils.getPageResult(pageRequest, new PageInfo<Equipment>(records));

	}

	@Override
	public List<Equipment> selectByExampleWithBLOBs(EquipmentExample example) throws BOException {
		return equipmentMapper.selectByExampleWithBLOBs(example);

	}

	@Override
	public int updateByExampleWithBLOBs(Equipment record, EquipmentExample example) throws BOException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateByPrimaryKeyWithBLOBs(Equipment record) throws BOException {
		return equipmentMapper.updateByPrimaryKeyWithBLOBs(record);

	}


}
